<?php

	$active_user_id = $_COOKIE["active_user_id"];
	$active_user_first_name = $_COOKIE["active_user_first_name"];
	$active_user_last_name = $_COOKIE["active_user_last_name"];
	$active_user_level = $_COOKIE["active_user_level"];
	
	$smarty->assign("active_user_id",$active_user_id);
	$smarty->assign("active_user_first_name",$active_user_first_name);
	$smarty->assign("active_user_last_name",$active_user_last_name);
	$smarty->assign("active_user_level",$active_user_level);	

	if($get_action=="logout") {

		$get_action = "view";
		$get_item = "home";

		$smarty->assign("active_user_id","");
		$smarty->assign("active_user_first_name","");
		$smarty->assign("active_user_last_name","");
		$smarty->assign("active_user_level",0);	

		setcookie("active_user_id","",time()-3600);			
		setcookie("active_user_first_name","",time()-3600);	
		setcookie("active_user_last_name","",time()-3600);
		setcookie("active_user_level",0,time()-3600);

		array_push($ctl_status,"You have successfully logged out.");
			
	}

	if($post_form_id=="login") {
		
		$get_action = "view";
		$get_item = "home";
		
		$login_user_id = strtolower($_POST["login_user_id"]);
		$login_password = $_POST["login_password"];
		
		$user_current = UserPeer::retrieveByPK($login_user_id);
		
		if($user_current!=null) {
		
			$active_user_id = $user_current->getId();
			$active_user_first_name = $user_current->getFirstName();
			$active_user_last_name = $user_current->getLastName();
			$active_user_password = $user_current->getPassword();
			$active_user_level = $user_current->getLevel();
			
			if($login_password==$active_user_password and $active_user_level>=10) {
				$smarty->assign("active_user_id",$active_user_id);
				$smarty->assign("active_user_first_name",$active_user_first_name);
				$smarty->assign("active_user_last_name",$active_user_last_name);
				$smarty->assign("active_user_level",$active_user_level);								
				setcookie("active_user_id",$active_user_id,time()+3600);			
				setcookie("active_user_first_name",$active_user_first_name,time()+3600);
				setcookie("active_user_last_name",$active_user_last_name,time()+3600);
				setcookie("active_user_level",$active_user_level,time()+3600);
				array_push($ctl_status,"You have successfully logged in.");
			} else {
				$smarty->assign("active_user_id","");
				$smarty->assign("active_user_first_name","");
				$smarty->assign("active_user_last_name","");
				$smarty->assign("active_user_level",0);
				setcookie("active_user_id","",time()-3600);			
				setcookie("active_user_first_name","",time()-3600);
				setcookie("active_user_last_name","",time()-3600);
				setcookie("active_user_level",0,time()-3600);
			}
		
		}
		
	}


?>
